package com.crm.web.admin;

import com.crm.dto.CourseDeleteIdsDto;
import com.crm.dto.CoursePageDto;
import com.crm.entity.TbCourse;
import com.crm.result.PageResult;
import com.crm.result.Result;
import com.crm.service.CourseService;
import com.crm.vo.TbCourseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 课程
 */
@RestController
@RequestMapping("/clues/course")
@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;

    //课程分页查询
    @GetMapping("/list")
    public Result list(CoursePageDto coursePageDto){

        PageResult pageResult =courseService.list(coursePageDto);

        return Result.success(pageResult);
    }
    //新增课程
    @PostMapping
    public Result save(@RequestBody CoursePageDto coursePageDto ){
        courseService.save(coursePageDto);
        return Result.success();
    }
    //删除课程
    @DeleteMapping
    public Result CourseDeleteId(@RequestBody CourseDeleteIdsDto courseDeleteIdsDto){
        courseService.CourseDeleteId(courseDeleteIdsDto);
        return Result.success();
    }
    //根据id查询课程
    @GetMapping("/{id}")
    public Result CourseById(@PathVariable Long id){
        TbCourseVo tbCourseVo =courseService.CourseById(id);
        return Result.success(tbCourseVo);
    }

    //修改
    @PutMapping
    public Result update(@RequestBody TbCourse tbCourse){
        courseService.update(tbCourse);
        return Result.success();
    }
}
